/*
 * Villager.h
 *
 *  Created on: 25.1.2013
 *      Author: Travis


 Status changing
 
 STATUS_READY (default) - entity is waiting for new job (it doesn't move)
 When function setWork is called from master building of this entity than
 save pointer to building witch have to be constructed and set status STATUS_NEWJOB.
 When pointer to target is NULL set default status STATUS_READY.
 All status chck is in AIFunction.
 
 STATUS_NEWJOB - there is something to do :] so call goWork function, in this function
 there is calling of goTo function to find new way with pathFinder -> entity starts move.

 STATUS_GOWORK - entity is on way to target, in this case chck in time intervals status
 of target building and set status to STATUS_DONE when building is in status STATUS_READY.
 (ex.: that means construction of new building has been done with another entity)

 STATUS_WORKING - set in control when moving is done (control changes only STATUS_GOWORK to STATUS_WORKING
 and STATUS_GOHOME to STATUS_READY). 
 Call doWork function (ex.: Builder: where entity increases age of target building in time intervals till
 age < 100 (MAX_AGE const). When age of building is greater than MAX_AGE set status to STATUS_DONE)

 STATUS_DONE - work is done so call goHome function which get way back home with pathFinder
 and set status to STATUS_GOHOME.

 Finally control set status to STATUS_BACKHOME and AIfunction call backHome function.
 backHome set status to STATUS_READY

 Ex.: entity lumberjack
 STATUS_READY
 master->setWork(*tree);
 STATUS_NEWJOB
 this->goWork(); (find way to tree and start move)
 STATUS_GOWORK (entity moving to target)
 this->goingWork(); (chck tree status)
 STATUS_WORKING
 this->doWork(); (cut wood)
 STATUS_DONE
 this->goHome(); (find way back home)
 STATUS_GOHOME
 this->goingHome(); (chck something on way home)
 STATUS_BACKHOME
 this->backHome(); (store wood)
 STATUS_READY
 */

#pragma once

#ifdef _WIN32
#include <windows.h>
#include "SDL_thread.h"
#else
#include "SDL/SDL_thread.h"
#endif

#include "../../Entity.h"
#include "../dynamicEntity.h"
#include "time.h"
#include <list>
#include <iostream>
#include <cmath>

#define PI 3.14159265

class Villager: public dynamicEntity
{
public:
	Villager(glm::vec3 _Pos, float _r, float _speed, std::string _Name,
			std::string _modelFName, ModelPool *_mPool, PathFinder *_pathfinder,
			Terrain::Terrain *_ter);
	virtual ~Villager();

	// move with entity to position
	virtual void goTo(glm::vec2 pos);

	Entity *getOwner();
	void setOwner(Entity *entity);

	virtual void control(float t);

	// ai default
	// set new work (change status to STATUS_NEWJOB)
	virtual void setWork();

	// working
	virtual void doWork();

	// set new movevector (using gpTo function)
	// and find way home
	virtual void goHome();

	// set movevector (using goTo)
	// find way to target
	virtual void goWork();

	// call during move to target
	virtual void goingWork();

	// call during move back home
	virtual void goingHome();

	// call when is entity back home
	// than set to ready
	virtual void backHome();

	// main logic AI
	virtual void AIFunction();

protected:

	// pointer to owner of this villager
	// when NULL he's free :)
	Entity *owner;
};
